;; ============================   chaos :: [RL]   ============================

;; This file is used for low-level drawing functions
;; Note, however, that functions defined here should be high-level enough to
;; take game coordinates as arguments.

(defparameter *font-size* (v- *tile-size* #(2 2)))


;;; It might be better to do this with an assoclist or hash table, but I hate
;;; both of those things. -- Past Alyssa
;;; Or rather, I don't want to mess around with them. -- Future Alyssa
(defun get-font (size)
  (case size
    (8  sdl:*font-8x8*)
    (t  (error "[drawing.lisp]: no font found with size ~d." size))))

(defparameter sdl:*default-font* (get-font *font-size*))
;;; Not entirely sure what this function does; it's a magic necessary SDL thing.
(sdl:initialise-default-font)

;;; The draw method of a tile clears the target location with this color before
;;; blitting the object.
;;; Addendum: that's a stupid way to do it. D-D-D-DEPRECATED!
;(defparameter *floor-color* sdl:*black*)

;; Despite the function and parameter names, `char' is supposed to be a one-element string.
;; Multi-element strings will work, but don't do that.
(defun draw-char (char &key at
			 (floor sdl:*black*) (color sdl:*white*) (font sdl:*default-font*)
			 (surface sdl:*default-display*))
  (let ((point (game->drawloc at))
	(rect  (game->sdlrect at)))
    
    ;; Clear the tile first
    (sdl:draw-box rect :color floor)

    ;; Draw the character with a one-pixel border in this location
    (sdl:draw-string-solid char point :color color :font font)))


;; This has to be a method because some stupid programmer decided that it should also
;; work on meatbags.
(defmethod hilight ((point sequence) color &key (surface sdl:*default-display*))
  (sdl:draw-rectangle (game->sdlrect point) :color color))

(defun random-color ()
  (sdl:color :r (random 255) :g (random 255) :b (random 255)))
